﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %>

<%@ Register Assembly="GeoWeb.Controls.WebGrid" Namespace="GeoWeb.Controls.WebGrid"
    TagPrefix="GeoStar" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CXL_WebControl.WebGrid</title>
</head>
<body style="overflow: hidden; margin: 10px;">
    <form id="form1" runat="server">
    翻页：<select id="select_Page" style="width: 80px;" onchange="g.gotoPage(this.value);">
    </select>&nbsp;&nbsp;&nbsp;
    皮肤切换：<select id="select_Skin" style="width: 80px;" onchange="g.reLoadSkin(this.value, this.options[this.selectedIndex].getAttribute('path'));">
        <option value="default">default</option>
        <option value="Pink" path="Skins/Pink/Pink.css">Pink</option>
        <option value="Test" path="Skins/Test/Test.css">Test</option>
    </select>&nbsp;&nbsp;&nbsp;
    获取选中的行：<input type="button" onclick="getSelectedRows();" value="getSelectedRows" />
    <br />
    
    <GeoStar:WebGrid ID="WebGrid1" runat="server" AutoLoadData="True"
        DelayLoadData="False" DelayLoadTime="200" Width="800" Height="400" AutoGenerateColumns="True"
        MultiSelect="True" OnWebGridRefresh="WebGrid1_OnWebGridRefresh" PageSize="20"
        RowMultiLine="False" ShowCheckBox="True" PageIndex="1" FontSize="14"
        SortName="ISO" SortOrder="ASC" OnWebGridColumnCreated="WebGrid1_OnWebGridColumnCreated"
        PagerFormatString="共{0}条, 每页{1}条, 共{2}页, 第{3}页"
        MemoryStateAfterRefresh="True" 
        onwebgridcellrendering="WebGrid1_WebGridCellRendering" 
        onwebgridaftercelledit="WebGrid1_WebGridAfterCellEdit">

        <RightFrozenColumns>
            <GeoStar:WebGridButtonColumn Title="操作" Text="操作" Align="Center" CallBack="Btn_Click" />
            <GeoStar:WebGridImageColumn ImageUrl="imgs/delete.gif" Align="Center" Title="图片" />
            <GeoStar:WebGridButtonColumn Align="Left" ResizeAble="True" Text="" Title="" 
                Visible="True" Width="100" />
        </RightFrozenColumns>
        <CallBacks OnBeforeLoad="OnBeforeLoad" OnAfterRefresh="OnAfterRefresh" OnRowClick="OnRowClick" />

    </GeoStar:WebGrid>

    </form>
</body>
</html>
<script type="text/javascript">
    var r = 0;
    var g = WebGrid1.webGrid;
    var Btn_Click = function (o, a) {
        alert(a.data['Name']);
    };
    var OnBeforeLoad = function () {
        window.onresize();
        g.multiSelect = false;
        g.setQueryParams({ UID: '11' });
    };
    var OnAfterRefresh = function (o, a) {
        if (r == 0) {
            var select_Page = document.getElementById("select_Page");
            select_Page.options.length = 0;
            select_Page.options.add(new Option("gotoPage"));
            for (var i = 1; i <= g.pageCount; i++) {
                select_Page.options.add(new Option(i, i));
            }
            r++;
        }
    };
    var OnRowClick = function (o, a) {
        //alert("lastCurrentRow-index: " + o.lastCurrentRow.index + "\ncurrentRow-index: " + o.currentRow.index);
    };

    window.onresize = function () {
        var w = document.documentElement.clientWidth || document.body.clientWidth,
            h = document.documentElement.clientHeight || document.body.clientHeight;
        g.reSizeTo({
            width: w - 20,
            height: h - 43
        });
    };

    if (!g.autoLoadData) {
        window.setTimeout(function () { g.refresh(); alert('延时5秒钟加载数据！'); }, 5000);
    }

    function getSelectedRows() {
        var rows = g.getSelectedRows();
        if (rows.length > 0) {
            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                var _arr = ['"index":"' + rows[i].index + '"'];
                for (var it in rows[i].data) {
                    _arr.push('"' + it + '":"' + rows[i].data[it] + '"');
                }
                arr.push('  {' + _arr.join() + '}');
            }
            var str = '[\n' + arr.join(',\n') + '\n]';
            alert(str);
            window.eval('(' + str + ')');
        }
        else {
            alert('没有勾选任何行!');
        }
    }
</script>
